package org.ami.onlineschool.model;

import java.io.File;
import java.text.DateFormatSymbols;
import java.util.UUID;

/**
 * @author FaraZ
 *
 */
public class Assignment implements Comparable<Assignment>{
	private int month;
	private int day;
	private String subject;
	private String message;
	private String id = UUID.randomUUID().toString();
	
	public static String ATTACHMENTS_FOLDER_NAME = "attachments";
	
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getDay() {
		return day;
	}
	public void setDay(int day) {
		this.day = day;
	}
	@Override
	public String toString() {
		return getMonthName() + " - " + day;
	}
	
	private String getMonthName() {
	    String monthName = "invalid";
	    DateFormatSymbols dfs = new DateFormatSymbols();
	    String[] months = dfs.getMonths();
	    if (month < months.length) {
	    	monthName = months[month - 1];
	    }
	    return monthName;
	}
	
	@Override
	public int compareTo(Assignment otherAssg) {

		int monthResult = (month<otherAssg.month ? -1 : (month==otherAssg.month ? 0 : 1));
		if(monthResult == 0)
			return (day<otherAssg.day ? -1 : (day==otherAssg.day ? 0 : 1));
		
		return monthResult;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * @return relative path to attachments folder. 
	 */
	public String getAttachmentsFolder() {
		return File.separator + ATTACHMENTS_FOLDER_NAME + 
				File.separator + getId();
	}
	
	
}
